#include "Recv_Task.h"
#include "TcpClient.h"
#include "Return_Task.h"
#include <sys/socket.h>
#include <unistd.h>
#include <QDebug>
Recv_Task::Recv_Task(CTcpClient *pTcpClient,Return_Task *return_task):m_pTcpClient(pTcpClient),m_return_task(return_task)
{
    m_hTcpSock =0;
}

Recv_Task::~Recv_Task(void)
{
}

void Recv_Task::set_socket( int TcpSock )
{
	m_hTcpSock = TcpSock;
}

int Recv_Task::svc()
{
    discard();
	int  lnRecvDataLen = 0;	
	char lszRecvBuff[2048] = {0};

    while (true)
	{
		lnRecvDataLen = recv(m_hTcpSock,(char*)lszRecvBuff,2048,0);
		if(lnRecvDataLen <= 0)
		{
            qDebug(QString("recv ....").toLocal8Bit().data());
            m_pTcpClient->DisConnect();

            return 1;
		}
		if (m_return_task)
		{
			m_return_task->putq(std::string(lszRecvBuff,lnRecvDataLen));
			memset(lszRecvBuff,0,2048);
		}
	}
    return 1;
}

int Recv_Task::close()
{
    return 1;
}
